<template>

  <el-form ref="form" :model="LoginForm" label-position="top" size="small">
    <el-card class="box-card" shadow="hover">
      <div slot="header" class="clearfix">
        <span>登录后台</span>
      </div>
      <el-form-item label="账号">
        <el-input v-model="LoginForm.username"></el-input>
      </el-form-item>
      <el-form-item label="密码">
        <el-input type="password" v-model="LoginForm.password"></el-input>
      </el-form-item>
      <el-form-item>
        <el-button type="primary" @click="login()">登录</el-button>
      </el-form-item>
      </el-card>
    </el-form>

</template>

<script>
export default {
  data() {
    return {
      LoginForm: {
        username: 'admin',
        password:'123456'
      }
    }
  },
  created() {
    // this.login()
  },
  methods:{
    async login(){
      // console.log(this.$ajax)
      // console.log(11111)
      const {data:res} = await this.$ajax.post('http://49.234.154.118/api/login/login',this.LoginForm)
      // console.log(res);
      // 登录成功以后提示信息 message组件
      if (res.code == 1){
        this.$msg.success(res.msg)
        // 存储session
        window.sessionStorage.setItem('token',res.token)
        // 跳转到后台首页
        this.$router.push('/')
      }else{
        this.$msg.error(res.msg)
      }




    }
  }
}
</script>

<style scoped>
.clearfix{
  text-align: center;
}
form{
  width: 300px;
  margin:0 auto;
  position: relative; /*脱离文档流*/
  top: 50%;
  transform: translateY(-50%);
}
</style>